package org.itboys.member;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.fuzion.service.FuzionMemberService;
import org.itboys.fuzion.service.MemberTwoCodeService;
import org.itboys.weixin.tools.WeixinUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
/**
 * 大乱斗微信相关
 * @author weisky
 *
 * 2016年4月14日
 */
@RestController 
@RequestMapping("/fuzion/weixin") 
public class FuzionTwoCodeController extends BaseController{

	@Autowired
	private MemberTwoCodeService memberTwoCodeService;
	@Autowired
	private FuzionMemberService fuzionMemberService;
	
	/**
	 * 分享的二维码页面
	 * @param paramId
	 * @param model
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/createMyWeixinTwoCode") 
	public ModelAndView createMyWeixinTwoCode(@RequestParam(required=false) Long paramId, Model model,
			HttpServletRequest request, HttpServletResponse response){
		
		Long memberId = (Long) request.getSession().getAttribute("memberId");
		if(memberId == null){//如果之前没有存入session  则进入
			if(paramId != null){
				fuzionMemberService.setSessionMember(paramId, request, response);
			}else{
				return new ModelAndView("/error");
			}
		}
		
		String twocode = memberTwoCodeService.createMemberTwoCodeSaveSer(memberId);
		if(StringUtils.isBlank(twocode)){
			return new ModelAndView("/error");
		}
		model.addAttribute("twoCodeUrl", twocode);//二维码地址
		
		return new ModelAndView("/site/twocode");
	}


	
}
